package cn.myword.wordTemple.tools;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class ParamGenerate {

    public static String generate(String type) {
        String res=type;
        Random random=new Random();
        if ("String".equals(type)){
            return type;
            //return generateRandomString(10);
        }else if("Integer".equals(type)){
            return random.nextInt(500)+"";
        }else if(type.contains("date")||"timestamp".equals(type)){
            return genDate();
        }else if("Double".equals(type)){
            return random.nextDouble(50)+"";
        }
        return res;
    }


    public static String genDate(){
        // 创建一个SimpleDateFormat对象，指定输出格式
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // 获取当前日期时间
        Date currentDate = new Date();
        // 格式化当前日期时间
        return formatter.format(currentDate);
    }
    public static String generateRandomString(int length) {
        // 定义可用字符
        String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
        StringBuilder result = new StringBuilder();
        Random random = new Random();
        // 生成随机字符串
        for (int i = 0; i < length; i++) {
            int index = random.nextInt(characters.length());
            result.append(characters.charAt(index));
        }
        return result.toString();
    }
}
